css: Refactor code to do property lookups earlier
authorBenjamin Otte <otte@redhat.com>
Mon, 16 May 2011 21:37:29 +0000 (23:37 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 18 May 2011 20:17:57 +0000 (22:17 +0200)
We want to ook up the property in the CSS parser, so we can do fancy
things with it. We currently don't but we want to later.

gtk/gtkcssprovider.c
gtk/gtkstyleproperties.c
gtk/gtkstylepropertiesprivate.h

index fd2696a32ebb410160216ff1a422192028912b53..e93c894ef506fd6361fdc08c524ae3a32f972ec1 100644 (file)
@@ -33,6 +33,7 @@
 #include "gtksymboliccolor.h"
 #include "gtkstyleprovider.h"
 #include "gtkstylecontextprivate.h"
+#include "gtkstylepropertiesprivate.h"
 #include "gtkbindings.h"
 #include "gtkmarshalers.h"
 #include "gtkprivate.h"
@@ -1130,20 +1131,15 @@ gtk_css_provider_get_style (GtkStyleProvider *provider,
 
       while (g_hash_table_iter_next (&iter, &key, &value))
         {
-          gchar *prop = key;
+          GParamSpec *pspec;
 
-          /* Properties starting with '-' may be both widget style properties
-           * or custom properties from the theming engine, so check whether
-           * the type is registered or not.
-           */
-          if (prop[0] == '-' &&
-              !gtk_style_properties_lookup_property (prop, NULL, NULL))
+          if (!gtk_style_properties_lookup_property (key, NULL, &pspec))
             continue;
 
-          gtk_style_properties_set_property (props,
-                                             key,
-                                             _gtk_css_selector_get_state_flags (info->selector),
-                                             value);
+          _gtk_style_properties_set_property_by_pspec (props,
+                                                       pspec,
+                                                       _gtk_css_selector_get_state_flags (info->selector),
+                                                       value);
         }
     }
 
index aeabb95ff921f0305929a26d2e9ac0c2c43cf5d4..27e73929da55b8e15a6ae67d5fc82ab1d6f19d3b 100644 (file)
@@ -602,66 +602,43 @@ gtk_style_properties_lookup_color (GtkStyleProperties *props,
   return g_hash_table_lookup (priv->color_map, name);
 }
 
-/**
- * gtk_style_properties_set_property:
- * @props: a #GtkStyleProperties
- * @property: styling property to set
- * @state: state to set the value for
- * @value: new value for the property
- *
- * Sets a styling property in @props.
- *
- * Since: 3.0
- **/
 void
-gtk_style_properties_set_property (GtkStyleProperties *props,
-                                   const gchar        *property,
-                                   GtkStateFlags       state,
-                                   const GValue       *value)
+_gtk_style_properties_set_property_by_pspec (GtkStyleProperties *props,
+                                             GParamSpec         *pspec,
+                                             GtkStateFlags       state,
+                                             const GValue       *value)
 {
   GtkStylePropertiesPrivate *priv;
-  PropertyNode *node;
   PropertyData *prop;
   GType value_type;
   GValue *val;
 
-  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
-  g_return_if_fail (property != NULL);
-  g_return_if_fail (value != NULL);
-
   value_type = G_VALUE_TYPE (value);
-  node = property_node_lookup (property);
 
-  if (!node)
-    {
-      g_warning ("Style property \"%s\" is not registered", property);
-      return;
-    }
-
-  if (node->pspec->value_type == GDK_TYPE_RGBA ||
-      node->pspec->value_type == GDK_TYPE_COLOR)
+  if (pspec->value_type == GDK_TYPE_RGBA ||
+      pspec->value_type == GDK_TYPE_COLOR)
     {
       /* Allow GtkSymbolicColor as well */
       g_return_if_fail (value_type == GDK_TYPE_RGBA ||
                         value_type == GDK_TYPE_COLOR ||
                         value_type == GTK_TYPE_SYMBOLIC_COLOR);
     }
-  else if (node->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN)
+  else if (pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN)
     {
       /* Allow GtkGradient as a substitute */
       g_return_if_fail (value_type == CAIRO_GOBJECT_TYPE_PATTERN ||
                         value_type == GTK_TYPE_GRADIENT);
     }
   else
-    g_return_if_fail (node->pspec->value_type == value_type);
+    g_return_if_fail (pspec->value_type == value_type);
 
   priv = props->priv;
-  prop = g_hash_table_lookup (priv->properties, node->pspec);
+  prop = g_hash_table_lookup (priv->properties, pspec);
 
   if (!prop)
     {
       prop = property_data_new ();
-      g_hash_table_insert (priv->properties, node->pspec, prop);
+      g_hash_table_insert (priv->properties, pspec, prop);
     }
 
   val = property_data_get_value (prop, state);
@@ -679,6 +656,43 @@ gtk_style_properties_set_property (GtkStyleProperties *props,
   g_value_copy (value, val);
 }
 
+/**
+ * gtk_style_properties_set_property:
+ * @props: a #GtkStyleProperties
+ * @property: styling property to set
+ * @state: state to set the value for
+ * @value: new value for the property
+ *
+ * Sets a styling property in @props.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_properties_set_property (GtkStyleProperties *props,
+                                   const gchar        *property,
+                                   GtkStateFlags       state,
+                                   const GValue       *value)
+{
+  PropertyNode *node;
+
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
+  g_return_if_fail (property != NULL);
+  g_return_if_fail (value != NULL);
+
+  node = property_node_lookup (property);
+
+  if (!node)
+    {
+      g_warning ("Style property \"%s\" is not registered", property);
+      return;
+    }
+
+  _gtk_style_properties_set_property_by_pspec (props,
+                                               node->pspec,
+                                               state,
+                                               value);
+}
+
 /**
  * gtk_style_properties_set_valist:
  * @props: a #GtkStyleProperties
index 91dc72f6e9471e03a49d6bf8320f47eea8d90320..f4cea2d44ba26ac20a870b114edc154cf3ba792c 100644 (file)
 
 G_BEGIN_DECLS
 
-const GValue * _gtk_style_properties_peek_property (GtkStyleProperties *props,
-                                                    const gchar        *prop_name,
-                                                    GtkStateFlags       state);
+const GValue * _gtk_style_properties_peek_property         (GtkStyleProperties *props,
+                                                            const gchar        *prop_name,
+                                                            GtkStateFlags       state);
+
+void           _gtk_style_properties_set_property_by_pspec (GtkStyleProperties *props,
+                                                            GParamSpec         *pspec,
+                                                            GtkStateFlags       state,
+                                                            const GValue       *value);
 
 G_END_DECLS